home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / winsrc.arc / SELECT.C < prev    next >
C/C++ Source or Header  |  1991-06-16  |  5KB  |  166 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: Select.c
  4.  
  5.     PURPOSE: Contains library routines for selecting a region
  6.  
  7.     FUNCTIONS:
  8.  
  9.     StartSelection(HWND, POINT, LPRECT, int) - begin selection area
  10.     UpdateSelection(HWND, POINT, LPRECT, int) - update selection area
  11.     EndSelection(POINT, LPRECT) - end selection area
  12.     ClearSelection(HWND, LPRECT, int) - clear selection area
  13.  
  14. *******************************************************************************/
  15.  
  16. #include "windows.h"
  17. #include "select.h"
  18.  
  19. /****************************************************************************
  20.  
  21.     FUNCTION: StartSelection(HWND, POINT, LPRECT, int)
  22.  
  23.     PURPOSE: Begin selection of region
  24.  
  25. ****************************************************************************/
  26.  
  27. int FAR PASCAL StartSelection(hWnd, ptCurrent, lpSelectRect, fFlags)
  28. HWND hWnd;
  29. POINT ptCurrent;
  30. LPRECT lpSelectRect;
  31. int fFlags;
  32. {
  33.     if (lpSelectRect->left != lpSelectRect->right ||
  34.         lpSelectRect->top != lpSelectRect->bottom)
  35.     ClearSelection(hWnd, lpSelectRect, fFlags);
  36.  
  37.     lpSelectRect->right = ptCurrent.x;
  38.     lpSelectRect->bottom = ptCurrent.y;
  39.  
  40.     /* If you are extending the box, then invert the current rectangle */
  41.  
  42.     if ((fFlags & SL_SPECIAL) == SL_EXTEND)
  43.     ClearSelection(hWnd, lpSelectRect, fFlags);
  44.  
  45.     /* Otherwise, set origin to current location */
  46.  
  47.     else {
  48.     lpSelectRect->left = ptCurrent.x;
  49.     lpSelectRect->top = ptCurrent.y;
  50.     }
  51.     SetCapture(hWnd);
  52. }
  53.  
  54. /****************************************************************************
  55.  
  56.     FUNCTION: UpdateSelection(HWND, POINT, LPRECT, int) - update selection area
  57.  
  58.     PURPOSE: Update selection
  59.  
  60. ****************************************************************************/
  61.  
  62. int FAR PASCAL UpdateSelection(hWnd, ptCurrent, lpSelectRect, fFlags)
  63. HWND hWnd;
  64. POINT ptCurrent;
  65. LPRECT lpSelectRect;
  66. int fFlags;
  67. {
  68.     HDC hDC;
  69.     short OldROP;
  70.  
  71.     hDC = GetDC(hWnd);
  72.  
  73.     switch (fFlags & SL_TYPE) {
  74.  
  75.     case SL_BOX:
  76.         OldROP = SetROP2(hDC, R2_NOTXORPEN);
  77.         MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  78.         LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  79.         LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  80.         LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  81.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  82.         LineTo(hDC, ptCurrent.x, lpSelectRect->top);
  83.         LineTo(hDC, ptCurrent.x, ptCurrent.y);
  84.         LineTo(hDC, lpSelectRect->left, ptCurrent.y);
  85.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  86.         SetROP2(hDC, OldROP);
  87.         break;
  88.     
  89.     case SL_BLOCK:
  90.         PatBlt(hDC,
  91.         lpSelectRect->left,
  92.         lpSelectRect->bottom,
  93.         lpSelectRect->right - lpSelectRect->left,
  94.         ptCurrent.y - lpSelectRect->bottom,
  95.         DSTINVERT);
  96.         PatBlt(hDC,
  97.         lpSelectRect->right,
  98.         lpSelectRect->top,
  99.         ptCurrent.x - lpSelectRect->right,
  100.         ptCurrent.y - lpSelectRect->top,
  101.         DSTINVERT);
  102.         break;
  103.     }
  104.     lpSelectRect->right = ptCurrent.x;
  105.     lpSelectRect->bottom = ptCurrent.y;
  106.     ReleaseDC(hWnd, hDC);
  107. }
  108.  
  109. /****************************************************************************
  110.  
  111.     FUNCTION: EndSelection(POINT, LPRECT)
  112.  
  113.     PURPOSE: End selection of region, release capture of mouse movement
  114.  
  115. ****************************************************************************/
  116.  
  117. int FAR PASCAL EndSelection(ptCurrent, lpSelectRect)
  118. POINT ptCurrent;
  119. LPRECT lpSelectRect;
  120. {
  121.     lpSelectRect->right = ptCurrent.x;
  122.     lpSelectRect->bottom = ptCurrent.y;
  123.     ReleaseCapture();
  124. }
  125.  
  126. /****************************************************************************
  127.  
  128.     FUNCTION: ClearSelection(HWND, LPRECT, int) - clear selection area
  129.  
  130.     PURPOSE: Clear the current selection
  131.  
  132. ****************************************************************************/
  133.  
  134. int FAR PASCAL ClearSelection(hWnd, lpSelectRect, fFlags)
  135. HWND hWnd;
  136. LPRECT lpSelectRect;
  137. int fFlags;
  138. {
  139.     HDC hDC;
  140.     short OldROP;
  141.  
  142.     hDC = GetDC(hWnd);
  143.     switch (fFlags & SL_TYPE) {
  144.  
  145.     case SL_BOX:
  146.         OldROP = SetROP2(hDC, R2_NOTXORPEN);
  147.         MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  148.         LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  149.         LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  150.         LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  151.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  152.         SetROP2(hDC, OldROP);
  153.         break;
  154.  
  155.     case SL_BLOCK:
  156.         PatBlt(hDC,
  157.         lpSelectRect->left,
  158.         lpSelectRect->top,
  159.         lpSelectRect->right - lpSelectRect->left,
  160.         lpSelectRect->bottom - lpSelectRect->top,
  161.         DSTINVERT);
  162.         break;
  163.     }
  164.     ReleaseDC(hWnd, hDC);
  165. }
  166.